package com.java.project1;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Serial {
    public static void main(String[] args) {
		
    	Serperson p1 =  new Serperson("Abani",35);
    	File f1 = new File("C:\\Users\\Apeksha\\workspace\\AbaniJava\\src\\com\\java\\project1\\person.txt");
    	
    	FileOutputStream fo=null;
    	ObjectOutputStream oo=null;
    	
    	try {
			fo = new FileOutputStream(f1);
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
    	try {
			oo = new ObjectOutputStream(fo);
			oo.writeObject(p1);
			oo.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	ObjectInputStream oi=null;
    	FileInputStream fi=null;
    	Serperson p2=null;
    	try {
			oi = new ObjectInputStream(new FileInputStream(f1));
			p2 =  (Serperson) oi.readObject();
			oi.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	System.out.println("name:"+p2.getName()+"age:"+p2.getAge());
    	System.out.println(p2);
	}
   
}